package cn.monkey.family.data.uc.user.role;

import cn.monkey.family.data.uc.role.Role;
import cn.monkey.family.data.uc.user.User;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;

import java.util.Collection;
import java.util.List;

@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface UserRoleMapper {

    UserRoleVo toVo(User user);

    default Collection<UserRole> toEntity(User user, Collection<Role> roles) {
        return roles.stream()
                .map(r -> {
                    UserRole userRole = new UserRole();
                    userRole.setUid(user.getId());
                    userRole.setRoleId(r.getId());
                    return userRole;
                })
                .toList();
    }

    List<UserRoleVo> toVos(List<User> users);
}
